<template>
	<el-dialog v-model="visible" title="群组信息" :close-on-click-modal="false">
		<el-form ref="dataFormRef" :model="dataForm" label-width="100px" :disabled="true">
			<el-form-item label="群头像" prop="headImage">
				<el-avatar shape="square" :size="100" :src="dataForm.headImage"></el-avatar>
			</el-form-item>
			<el-form-item label="群id" prop="id">
				<el-input v-model="dataForm.id"></el-input>
			</el-form-item>
			<el-form-item label="群名字" prop="name">
				<el-input v-model="dataForm.name"></el-input>
			</el-form-item>
			<el-form-item label="群主用户id" prop="ownerId">
				<el-input v-model="dataForm.ownerId"></el-input>
			</el-form-item>
			<el-form-item label="群主用户名" prop="ownerId">
				<el-input v-model="dataForm.ownerUserName"></el-input>
			</el-form-item>
			<el-form-item label="群公告" prop="notice">
				<el-input type="textarea" v-model="dataForm.notice"></el-input>
			</el-form-item>
			<el-form-item label="创建时间" prop="createdTime">
				<el-input v-model="dataForm.createdTime"></el-input>
			</el-form-item>
			<el-form-item v-show="dataForm.isBanned" label="是否被封禁" prop="isBanned">
				<ma-dict-label dict-type="boolean_type" :dict-value="dataForm.isBanned ? 1 : 0" />
			</el-form-item>
			<el-form-item v-show="dataForm.isBanned" label="被封禁原因" prop="reason">
				<el-input v-model="dataForm.reason"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button type="primary" @click="visible = false">确定</el-button>
		</template>
	</el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useGroupApi } from '@/api/im/group'

const emit = defineEmits(['refreshDataList'])

const visible = ref(false)
const dataFormRef = ref()

const dataForm = reactive({
	id: '',
	name: '',
	ownerId: '',
	ownerUserName: '',
	headImage: '',
	headImageThumb: '',
	notice: '',
	remark: '',
	isBanned: false,
	reason: '',
	createdTime: ''
})

const init = (id: number) => {
	visible.value = true
	getGroup(id)
}

const getGroup = (id: number) => {
	useGroupApi(id).then(res => {
		Object.assign(dataForm, res.data)
	})
}

defineExpose({
	init
})
</script>
